#include "StdAfx.h"
#include "MediaInfo.h"
#include "ReDir.h"

CMediaInfo::CMediaInfo(const char *lpFileName)
{
	CStringA str_enc;
	CFileInfoRedir FileInfo;

	TCHAR path[512];
	::GetCurrentDirectory(512,path);
	::GetModuleFileName(NULL, path, 512);
	TCHAR *tmp = _tcsrchr(path, '\\');
	*tmp = '\0';

	str_enc =path;
	str_enc += "\\codec\\";
	str_enc += "mplayer.exe -vo null -ao null -frames 0 -identify ";
	str_enc += "\"";
	str_enc += lpFileName;
	str_enc += "\"";

	FileInfo.StartChildProcess(str_enc, TRUE);
		Sleep(600);
	while (FileInfo.IsChildRunning()) {
		Sleep(100);
	};

	memset(&m_fileinfo, 0, sizeof(st_FileInfo));
	FileInfo.Format_msg();	
	m_fileinfo = FileInfo.get_fileinfo();
}

CMediaInfo::~CMediaInfo(void)
{
}

ULONG64	CMediaInfo::GetSeconds() const
{
#if 0 // pengl add [11/8/2008]
	return m_nLength >> 10;
#endif
	return (ULONG64)m_fileinfo.length; // in seconds
}

int	CMediaInfo::GetFrames() const
{
	ASSERT(FALSE);
	return 0;
}

int	CMediaInfo::GetHeight() const
{
	return m_fileinfo.v_height;
}

int	CMediaInfo::GetWidth() const
{
	return m_fileinfo.v_width;
}

float	CMediaInfo::GetFps() const
{
	return m_fileinfo.v_fps;
}

int	CMediaInfo::GetChannel() const
{
	return m_fileinfo.a_nch;
}

int	CMediaInfo::GetAspect() const
{
	return (int)m_fileinfo.v_aspect;
}

int	CMediaInfo::GetBitrate() const
{
	return m_fileinfo.v_bitrate;
}

char *CMediaInfo::GetVCodec() const	//fourcc
{
	return (char *)m_fileinfo.format;
}

char *CMediaInfo::GetACodec() const	//fourcc
{
	return (char *)m_fileinfo.a_codec;
}

int	CMediaInfo::GetSamplerate() const//audio samplerate
{
	return m_fileinfo.a_rate;
}

int	CMediaInfo::GetLength()	const //in seconds
{
	return (int)m_fileinfo.length;
}



